package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.MeCurriculumApi;
import com.jjb.www.http.glide.GlideApp;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class MeCurriculumAdapter extends AppAdapter<MeCurriculumApi.Bean> {

    public MeCurriculumAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeImageView mImgThumb;
        private ShapeTextView mTvStatus;
        private ShapeTextView mTvType;
        private ShapeTextView mTvTitle;
        private ShapeTextView mTvTime;
        private ShapeTextView mTvStudyLog;



        private ViewHolder() {
            super(R.layout.item_me_curriculum);
            mImgThumb = findViewById(R.id.img_thumb);
            mTvStatus = findViewById(R.id.tv_status);
            mTvType = findViewById(R.id.tv_type);
            mTvTitle = findViewById(R.id.tv_title);
            mTvTime = findViewById(R.id.tv_time);
            mTvStudyLog = findViewById(R.id.tv_study_log);
        }

        @Override
        public void onBindView(int position) {
            MeCurriculumApi.Bean bean = getItem(position);
            mTvTitle.setText(bean.getTitle());
            mTvTime.setText("过期时间："+bean.getTime());
            if ("未学习".equals(bean.getStudy_log())){
                mTvStudyLog.setText("学至：第一章第1节");
            }else {
                mTvStudyLog.setText("学至："+bean.getStudy_log());
            }
            GlideApp.with(getContext())
                    .load(bean.getThumb())
                    .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners((int) getResources().getDimension(R.dimen.dp_10))))
                    .into(mImgThumb);
            if (bean.getTime_status()==0){
                //过期
                mTvStatus.setVisibility(View.VISIBLE);
            }else {
                mTvStatus.setVisibility(View.GONE);
            }

            if (bean.getCate()==1){
                //继教
                mTvType.setBackgroundResource(R.mipmap.icon_jjkc);
                mTvType.setText("继教课程");
            }else {
                mTvType.setBackgroundResource(R.mipmap.icon_jxjy);
                mTvType.setText("岗前课程");
            }
        }
    }
}